var js = {};

js.loadedApps = {};
js.loadedStyleSheets = {};

js.loadStyleSheet = function(aModuleName){
    if(js.loadedStyleSheets[aModuleName])
        return true;
    js.loadedStyleSheets[aModuleName] = true;

    $.ajax({
        cache: false,
        dataType: 'text',
        async: false,
        data: '',
        success: function(data){
            var link = document.createElement('style');
            link['type'] = 'text/css';
            if($.support.style){
                var textNode = document.createTextNode(data);
                link.appendChild(textNode);
            }else
                link.styleSheet.cssText = data;
            document.getElementsByTagName('head')[0].appendChild(link);
        },
        type: 'POST',
        url:'cache/'+aModuleName+'_'+PLATFORM+'.css?'+(new Date().getTime())
    });
    return true;
};

js.loadModule = function(aModuleName, aSuccessHandler, aSync){
    if(js.loadedApps[aModuleName]){
        if(aSuccessHandler)
            aSuccessHandler();
        return true;
    }
    $.ajax({
        cache: false,
        dataType: 'script',
        async: aSync,
        data: '',
        success: function(){
            js.loadedApps[aModuleName] = true;
            if(aSuccessHandler)
                aSuccessHandler();
        },
        type: 'POST',
        url:'cache/'+aModuleName+'_'+PLATFORM+'.js?'+(new Date().getTime())
    });
    return true;
}

//$(function(){
    js.loadStyleSheet('all');
//    js.loadedApps['core'] = true;
//    js.loadedApps['rssreader'] = true;
    js.loadModule('core', function(){
        new core.Desktop({});
        window.desktop = core.desktop;
//        core.setTimeout(core.desktop, core.desktop.displayLogin, 5000);
        core.desktop.displayLogin();
    }, false);
//});

